<?php
   // header("Content-Type:text/html;charset=utf-8");
    $serverName = "bdm246562380.my3w.com";
    $userName = "bdm246562380";
    $password = "p081742lh";
    $dbName = "bdm246562380_db";

//    $data2 = $GLOBALS['HTTP_RAW_POST_DATA'];
    $data2 = file_get_contents('php://input');
    $data = json_decode($data2);

    echo json_encode($data,JSON_UNESCAPED_UNICODE);

    $customerName = $data->customerName;
//    $customerCode = $data->customerCode;
    $customerCode = "byjiasi";
    $customerPhone = $data->customerPhone;
    $freight = $data->freight;
    $freightAddress = $data->freightAddress;
    $freightPhone = $data->freightPhone;
    $otherInfo = $data->otherInfo[0]->remarks;


    $newTime =  date('Y-m-d H:i:s',time());
    $orderId = 'BY'.date('Y',time()).date('m',time()).date('d',time()).date('H',time()).date('i',time()).date('s',time()).'00001';

    // 创建连接
    $conn = new mysqli($serverName, $userName, $password, $dbName);
    mysqli_query($conn,"set names 'utf8'");//写库

    // 检测连接
    if ($conn->connect_error) {
        die("连接失败: " . $conn->connect_error);
    }
    $sql = "INSERT INTO orderInfo (orderId, customerName,customerCode,customerPhone,freight,freightAddress,freightPhone,otherInfo) 
            VALUES ( '"
        .$orderId."','"
        .$customerName."','"
        .$customerCode."','"
        .$customerPhone."','"
        .$freight."','"
        .$freightAddress."','"
        .$freightPhone."','"
        .$otherInfo."')";
        //$sql = "SELECT * FROM orderInfo";

        /**
         * Class outobj
         * 定义返回结果对象
         */
        class outobj{
            const success = '';
            const message = '';
            const data = '';
        }
        $outObj = new outobj();

        if ($conn->query($sql) == true) {
            $outObj->success = 'true';
            $outObj->message = '新纪录插入成功';
            $outObj->data = '';

            //JSON_UNESCAPED_UNICODE  不转码 中文
            echo json_encode($outObj,JSON_UNESCAPED_UNICODE);

        } else {
            $outObj->success = 'false';
            $outObj->message = '新纪录插入失败';
            $outObj->data = '';
            echo json_encode($outObj,JSON_UNESCAPED_UNICODE);
            //echo "Error: " . $sql . "<br>" . $conn->error;
        }

        $conn->close();
/**
 * Created by PhpStorm.
 * User: lihao
 * Date: 2017-12-20
 * Time: 14:38
 */
    ?>
